package com.frxuexi.park2303.user.adapter

import android.view.View
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.base.entity.MyApproveBean
import com.frxuexi.base.entity.NewsBeanItem
import com.frxuexi.base.entity.ParkBeanItem
import com.frxuexi.base.entity.VisitBeanItem
import com.frxuexi.park.R
import com.frxuexi.park.databinding.ItemParkBinding
import com.frxuexi.park2303.databinding.ItemNewsBinding
import com.frxuexi.visit.databinding.ItemVisitBinding

class MyApproveAdapter:BaseMultiItemQuickAdapter<MyApproveBean,BaseViewHolder>() {
    init {
        addItemType(0,R.layout.item_park)
        addItemType(1,com.frxuexi.visit.R.layout.item_visit)
        addItemType(2,com.frxuexi.park2303.R.layout.item_news)
    }

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemParkBinding>(viewHolder.itemView)
    }

    override fun convert(helper: BaseViewHolder, item: MyApproveBean) {
        when(item.itemType){
            0->{
                val parkBeanItem = item as ParkBeanItem
                val binding = DataBindingUtil.getBinding<ItemParkBinding>(helper.itemView)!!
                binding.bean=parkBeanItem
                binding?.parkStatus?.apply {
                    when(item?.spaceStatus){
                        "空闲"->{
                            setTextColor(context.resources.getColor(com.frxuexi.base.R.color.green)!!)
                            setBackgroundResource(com.frxuexi.base.R.drawable.shape_status)
                            binding.parkGroup.visibility=View.VISIBLE
                        }
                        "已占用"->{
                            setTextColor(context.resources.getColor(com.frxuexi.base.R.color.blue)!!)
                            setBackgroundResource(com.frxuexi.base.R.drawable.shape_zhanyong)
                            binding.parkGroup.visibility=View.GONE
                        }
                        "维护中","维修中"->{
                            setTextColor(context.resources.getColor(com.frxuexi.base.R.color.orange)!!)
                            setBackgroundResource(com.frxuexi.base.R.drawable.shape_weihu)
                            binding.parkGroup.visibility=View.GONE
                        }
                    }
                }

            }
            1->{
                val visitBeanItem = item as VisitBeanItem
                val binding = DataBindingUtil.getBinding<ItemVisitBinding>(helper.itemView)!!
                binding.bean=visitBeanItem

                binding.visitStatus.apply {
                    when(item.visitStatus){
                        "待审核"->{
                            setTextColor(context.getColor(com.frxuexi.base.R.color.darkorange))
                            setBackgroundResource(com.frxuexi.base.R.drawable.shape_weihu)
                            binding.visitGroup.visibility=View.VISIBLE
                        }
                        "驳回"->{
                            setTextColor(context.getColor(com.frxuexi.base.R.color.blue))
                            setBackgroundResource(com.frxuexi.base.R.drawable.shape_zhanyong)
                            binding.visitGroup.visibility=View.GONE
                        }
                        "已通过"->{
                            setTextColor(context.getColor(com.frxuexi.base.R.color.green))
                            setBackgroundResource(com.frxuexi.base.R.drawable.shape_status)
                            binding.visitGroup.visibility=View.GONE
                        }
                        "已完成"->{
                            setTextColor(context.getColor(com.frxuexi.base.R.color.darkgray))
                            setBackgroundResource(com.frxuexi.base.R.drawable.shape_solid_gray)
                            binding.visitGroup.visibility=View.GONE
                        }
                    }
                }

                if(item.requestParking){
                    binding.visitCar.setImageResource(com.frxuexi.base.R.drawable.ic_action_car)
                    binding.visitCarNo.setText("已申请车位")
                }else{
                    binding.visitCar.setImageResource(com.frxuexi.base.R.drawable.ic_action_nocar)
                    binding.visitCarNo.setText("未申请车位")
                }
            }
            2->{
                val newsBeanItem = item as NewsBeanItem
                val binding = DataBindingUtil.getBinding<ItemNewsBinding>(helper.itemView)!!
                binding.bean=newsBeanItem
            }
        }
    }
}